import moment from 'moment'

const nowDay = () => {
  let startDate = moment(new Date())
    .startOf('days')
    .format('YYYY-MM-DD HH:mm:ss')
  let endDate = moment(new Date()).endOf('days').format('YYYY-MM-DD HH:mm:ss')
  return [startDate, endDate]
}

const preDay = () => {
  let startDate = moment(new Date())
    .subtract(1, 'days')
    .startOf('days')
    .format('YYYY-MM-DD HH:mm:ss')
  let endDate = moment(new Date())
    .subtract(1, 'days')
    .endOf('days')
    .format('YYYY-MM-DD HH:mm:ss')
  return [startDate, endDate]
}

const preNumberDay = (number: number) => {
  let startDate = moment(new Date())
    .subtract(number, 'days')
    .startOf('days')
    .format('YYYY-MM-DD HH:mm:ss')
  let endDate = moment(new Date())
    .subtract(number, 'days')
    .endOf('days')
    .format('YYYY-MM-DD HH:mm:ss')
  return [startDate, endDate]
}
//选择前start天的开始到前end天结尾的时间范围
const getStartToEndDays = (start: number, end: number) => {
  let startDate = moment(new Date())
    .subtract(start, 'days')
    .startOf('days')
    .format('YYYY-MM-DD HH:mm:ss')
  let endDate = moment(new Date())
    .subtract(end, 'days')
    .endOf('days')
    .format('YYYY-MM-DD HH:mm:ss')
  return [startDate, endDate]
}

const nowWeek = () => {
  const startDate = moment()
    .week(moment().week())
    .startOf('week')
    .format('YYYY-MM-DD HH:mm:ss')
  const endDate = moment()
    .week(moment().week())
    .endOf('week')
    .endOf('days')
    .format('YYYY-MM-DD HH:mm:ss')
  return [startDate, endDate]
}

const preWeek = () => {
  const startDate = moment()
    .week(moment().week() - 1)
    .startOf('week')
    .format('YYYY-MM-DD HH:mm:ss')
  const endDate = moment()
    .week(moment().week() - 1)
    .endOf('week')
    .format('YYYY-MM-DD HH:mm:ss')
  return [startDate, endDate]
}

const nowMonth = () => {
  const startDate = moment()
    .month(moment().month())
    .startOf('month')
    .format('YYYY-MM-DD HH:mm:ss')
  const endDate = moment()
    .month(moment().month())
    .endOf('month')
    .format('YYYY-MM-DD HH:mm:ss')
  return [startDate, endDate]
}

const preMonth = () => {
  const startDate = moment()
    .month(moment().month() - 1)
    .startOf('month')
    .format('YYYY-MM-DD HH:mm:ss')
  const endDate = moment()
    .month(moment().month() - 1)
    .endOf('month')
    .format('YYYY-MM-DD HH:mm:ss')
  return [startDate, endDate]
}

const nowYear = () => {
  const startDate = moment()
    .year(moment().year())
    .startOf('year')
    .format('YYYY-MM-DD HH:mm:ss')
  const endDate = moment()
    .year(moment().year())
    .endOf('year')
    .format('YYYY-MM-DD HH:mm:ss')
  return [startDate, endDate]
}

const preYear = () => {
  const startDate = moment()
    .year(moment().year() - 1)
    .startOf('year')
    .format('YYYY-MM-DD HH:mm:ss')
  const endDate = moment()
    .year(moment().year() - 1)
    .endOf('year')
    .format('YYYY-MM-DD HH:mm:ss')
  return [startDate, endDate]
}

const getYearByNumber = (year: number) => {
  const startDate = moment()
    .year(year)
    .startOf('year')
    .format('YYYY-MM-DD HH:mm:ss')
  const endDate = moment()
    .year(year)
    .endOf('year')
    .format('YYYY-MM-DD HH:mm:ss')
  return [startDate, endDate]
}

export {
  preDay,
  nowDay,
  nowWeek,
  preWeek,
  nowMonth,
  preMonth,
  nowYear,
  preYear,
  getYearByNumber,
  preNumberDay,
  getStartToEndDays,
}
